/*
 * This file is part of Smart Route for S60 3rd Edition terminals
 * 
 * Copyright (C) 2006  Harri Salminen

 * This program free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 *(at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
 
#include <eikmenub.h>
#include <akncontext.h>
#include <akntitle.h>
#include <BAUTILS.H>
#include "SmartRouteAppUi.h"
#include "SmartRoute.rsg"
#include "SmartRoute.hrh"
#include "MainScreen.hrh"
#include "TripInfo.hrh"
#include "MainScreenView.h"
#include "RouteListBoxView.h"
#include "SettingItemListView.h"

CSmartRouteAppUi::CSmartRouteAppUi()
	{
	}

CSmartRouteAppUi::~CSmartRouteAppUi() 
	{
	delete iEngine;
	}


void CSmartRouteAppUi::InitializeContainersL()
	{
	iMainScreenView = CMainScreenView::NewL();
	AddViewL(iMainScreenView);
	SetDefaultViewL(*iMainScreenView);
	
	iRouteListBoxView = CRouteListBoxView::NewL();
	AddViewL(iRouteListBoxView);
	
	iSettingView = CSmartRouteSettingItemListView::NewL();
	AddViewL(iSettingView);
	}



void CSmartRouteAppUi::HandleCommandL( TInt aCommand )
	{
	switch ( aCommand )
		{ 
		case EAknSoftkeyExit:
		case EEikCmdExit:
			{
			SaveL();
			Exit();
			}
			break;
		default:
			break;
		}

	TBool commandHandled = EFalse;
	switch ( aCommand )
		{ 
		default:
			break;
		}
	
		
	if ( !commandHandled ) 
		{
		if ( aCommand == EAknSoftkeyExit || aCommand == EEikCmdExit)
			Exit();
		}
	}


void CSmartRouteAppUi::HandleResourceChangeL( TInt aType )
	{
	CAknViewAppUi::HandleResourceChangeL( aType );
	}
				
TKeyResponse CSmartRouteAppUi::HandleKeyEventL(
		const TKeyEvent& aKeyEvent,
		TEventCode aType )
	{
	return EKeyWasNotConsumed;
	}

void CSmartRouteAppUi::HandleViewDeactivation( const TVwsViewId& aViewIdToBeDeactivated, const TVwsViewId &aNewlyActivatedViewId )
	{
	CAknViewAppUi::HandleViewDeactivation( aViewIdToBeDeactivated, aNewlyActivatedViewId );
	}
 
void CSmartRouteAppUi::ConstructL()
	{
	BaseConstructL( EAknEnableSkin );
	InitializeContainersL();
	iEngine = CSmartRouteEngine::NewL();
	}

CSmartRouteEngine& CSmartRouteAppUi::EngineL()
    {
    if(iEngine)
        return *iEngine;
   	else
   		User::Leave(KErrNotReady);
    }
    
